package file;

import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 74646
 * Date: 2022-06-21
 * Time: 18:37
 */

// 按照字符进行读文件
public class Demo11 {
    public static void main(String[] args) {
        try(Reader reader = new FileReader("F:/测试/test.txt")) {
            // 按照字符读文件
            while (true){
                char[] buffer = new char[1024];
                int len = reader.read(buffer);
                if(len==-1){
                    break;
                }
                for (int i = 0; i < len; i++) {
                    System.out.print(buffer[i]+" ");
                }
                System.out.println();
                // 直接打印字符
                String s = new String(buffer,0,len); // 如果 byte 数组，还可以在后面指定字符编码
                System.out.println(s);
            }
        }catch (IOException e){
            e.printStackTrace();
        }
    }
}
